<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jquery.min.js"></script>
    <style>
        table {
            width: 500px;
            margin: 20px auto;
            text-align: center;
            padding: 0px;
        }
        
        #foot {
            width: 500px;
            margin: 3px auto;
        }
        
        #foot div {
            width: 200px;
            float: right;
        }
        
        thead {
            background-color: cornflowerblue;
        }
        
        table,
        td,
        th {
            padding: 0px;
            border-collapse: collapse;
            padding: 5px 3px;
            height: 20px;
            line-height: 20px;
            border-bottom: 1px solid #777;
        }
        
        .bgeven {
            background-color: rgba(35, 196, 129, 0.473);
        }
        
        .bgodd {
            background-color: beige;
        }
    </style>
</head>

<body>


    <table>
        <thead>
            <tr>
                <td>
                    <input type="checkbox" name="all" id="all">
                </td>
                <td>序号</td>
                <td>姓名</td>
                <td>年龄</td>
                <td>成绩</td>
                <td>
                    操作
                </td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    <input type="checkbox" name="item" id="" value="">
                </td>

                <td>1</td>
                <td>张三</td>
                <td>20</td>
                <td>90.5</td>
                <td>
                    <a href="javascript:void(0);">删除</a>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" name="item" id="" value="">
                </td>

                <td>2</td>
                <td>李四</td>
                <td>21</td>
                <td>89</td>
                <td>
                    <a href="javascript:void(0)">删除</a>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" name="item" id="" value="">
                </td>

                <td>3</td>
                <td>王五</td>
                <td>20</td>
                <td>60</td>
                <td>
                    <a href="javascript:void(0);">删除</a>
                </td>
            </tr>

            <tr>
                <td>
                    <input type="checkbox" name="item" id="" value="">
                </td>

                <td>4</td>
                <td>王刘</td>
                <td>15</td>
                <td>14</td>
                <td>
                    <a href="javascript:void(0);">删除</a>
                </td>
            </tr>
        </tbody>

    </table>
    <div id="foot">
        <button>反选</button>
        <button id="del">删除选中</button>
        <div id="price">
            <span>总分</span>
            <span id="total">0.0</span>
        </div>

    </div>

</body>

<script src="js/jquery-3.6.0.min.js"></script>
<script>
    let Sum = 0.0;


    // 全选
    $('[name="all"]').change(function() {
        $('[name="item"]').prop('checked', $('[name="all"]').prop('checked'));
        sum()
    });

    // 反选
    $('button:first').click(function() {
        $('[name=item]').map(function(i) {
            $($('[name=item]')[i]).prop('checked', !$($('[name=item]')[i]).prop('checked'));
        })
        All()
    });

    $('[name=item] , button:first , [name="all"]').change(function() {
        All()
        sum()
    });
    // 删除选中
    $('#del').click(function() {
        $('input[name=item]:checked').each(function() {
            $(this).closest('tr').remove()
        });
        sum()
    });
    //删除链接
    $('a').click(function() {
        $(this).closest('tr').remove()
        sum();
    })

    //通过item控制全选状态
    function All() {
        $('[name=item]:checked').length === $('[name=item]').length ? $('[name="all"]').prop('checked', true) : $('[name="all"]').prop('checked', false);
        sum()
    }
    //总计
    function sum() {
        Sum = 0;
        // $('#total').html(Sum.toFixed(1));
        $('[name=item]').each(function() {
            if ($(this).prop('checked')) {
                Sum += parseFloat($(this).closest('tr').children().eq(4).html());
            }
        });
        $('#total').html(Sum.toFixed(1));
    }
</script>


</html>